// src/stores/route.ts
import { defineStore } from "pinia";
import { generateRoutes } from "@/utils/routeGenerator";

export const useRouteStore = defineStore("route", {
  state: () => ({
    isRoutesLoaded: false,
  }),
  actions: {
    async loadDynamicRoutes() {
      // 从接口获取菜单数据
      const menuData = await JSON.parse(
        localStorage.getItem("menuList") || "[]"
      );
      const dynamicRoutes = generateRoutes(menuData);

      // 添加到主布局路由下
      dynamicRoutes.forEach((route) => {
        router.addRoute("Layout", route);
      });

      this.isRoutesLoaded = true;
    },
  },
});
